#include "stdio.h"


struct MyError
{
    char* cc;
    int len;
    int line;
    int num;
};

const int maxNum=100;
const int maxInput=105;
const int maxWordLen=16;

int min(int a, int b)
{
    if (a > b)
        return b;
    else
        return a;
}

char* readStr(char ss[maxInput],int &len)
{
    int i,j;
    char* result=new char[16];
    int sr_len=0;
    int lastIndex=-1;
    for( i=0;i<maxInput;i++)
    {
        if(ss[i]=='\0')
        {
            sr_len=i;
            break;
        }
        if(ss[i]=='\\')
        {
            lastIndex=i;
        }
    }
    len=min(maxWordLen,sr_len-lastIndex-1);
    for( i=sr_len-len,j=0;j<len;i++,j++)
    {
        result[j]=ss[i];
    }
    return result;
}

int isEqueal(MyError* error,char* cc,int len,int line)
{
    if(error->len!=len||error->line!=line)
    {
        return 0;
    }
    for(int i=0;i<len;i++)
    {
        if(error->cc[i]!=cc[i])
        {
            return 0;
        }
    }
    return 1;
}


int main(){
    int queue_len=0;
    MyError* queue[maxNum];

    char ss[maxInput];
    int line;


    int i,j;
    while (scanf("%s %d",ss,&line)!=EOF)
    {
        int len;
        char* cc=readStr(ss,len);

        //匹配结果
        int flag=1;
        //队列循环
        for( i=0;i<queue_len;i++)
        {
            if(isEqueal(queue[i],cc,len,line))
            {
                queue[i]->num++;
                flag=0;
                break;
            }
        }
        //没有匹配到
        if(flag)
        {
            MyError* e=new MyError;
            e->cc=cc;
            e->len=len;
            e->line=line;
            e->num=1;
            queue[queue_len]=e;
            queue_len++;
          
        }
    }

    //队列循环
    for( i=0;i<queue_len;i++)
    {
        MyError* ee=queue[i];
        if(i>=queue_len-8)
        {
            
            for( j=0;j<ee->len;j++)
            {
                printf("%c",ee->cc[j]);
            }
            printf(" %d %d\n",ee->line,ee->num);
        }
    

        delete ee->cc;
    }


    
}